/* export const COM_SHOW_LOADING = 'COM_SHOW_LOADING';
export const COM_SHOW_DIALOG = 'COM_SHOW_DIALOG'; */

import * as types from './types'

const state = {
    showDialog: false,
    showLoading: false,
    alertDialog:{
        show: false,
        title: '标题',
        buttontxt: '确定',
        content: 'sign'
    }
}





const getters = {
    showLoading: state => state.showLoading,
    showDialog: state => state.showDialog,
    alertDialog: state => state.alertDialog
};


const actions = {
    setShowLoading({ commit }, status) {
        console.log('set showLoading before')
        commit(types.COM_SHOW_LOADING, status)
    },

    setShowDialog({ commit }, status) {
        commit(types.COM_SHOW_DIALOG, status)
    },

    /* setAlertDialog({ commit }, res) {
        commit(types.COM_ALERT_DIALOG, res)
    }, */

    setAlertDialog({ commit }, res) {
        commit(types.COM_ALERT_DIALOG, res)
        //dispatch(types.COM_ALERT_DIALOG, res);
    },

}


const mutations = {


    [types.COM_SHOW_LOADING](state, status) {
        console.log('set showLoading after ' + status)
        state.showLoading = status;
    },

    [types.COM_SHOW_DIALOG](state, status) {

        state.showDialog = status;
    },

    [types.COM_ALERT_DIALOG](state, res) {
        state.alertDialog = {
            show: res.show || true,
            title: res.title || '温馨提示',
            buttontxt: res.buttontxt ||  '确定',
            content: res.content ||  'sign'
        };
    }

}


export default {
    state,
    actions,
    getters,
    mutations
}
